import { System } from "@/FrontProcessing/System/System";
import { debounce } from "stl-typescript";
import { devtool, IMouseEvent } from "cax-base";
import { GyActor } from "@/FrontProcessing/Actors/GyActor";

export const func_vertex_measure = debounce(
  (event: IMouseEvent, sys: System) => {
    const { position } = event;
    const ray: any = [position.x, position.y, 0.0];
    sys.app.selector.vtPicker.pick(ray, sys.app.renderer);
    if (sys.app.selector.vtPicker.getActors().length !== 0) {
      const selector = sys.app.selector.getPickedVTActors() as GyActor[];
      let r: any = null;
      selector.forEach((item) => {
        const t = sys.app.selector.pickVertexPoint(ray, item.partId);
        if (t) r = t;
      });
      devtool.success("当前吸附点", r);
      if (r) {
        sys._tempPointer.position = r.XYZ as any;
        sys._tempPointer.userdata.id = r.id;
        sys._tempPointer.userdata.XYZ = r.XYZ;
        sys._tempPointer.userdata.partId = r.partId;
        sys.model_add(sys._tempPointer);
      } else {
        sys.model_remove(sys._tempPointer);
      }
    }
  },
  50,
  false
);
